{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_excel('个股收盘价收益率成交量.xlsx', encoding='gbk', usecols=[0, 1, 5], parse_dates=[0]).sort_values(by=['股票代码', '日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "index_data = pd.read_csv('上证50收益率.csv', encoding='gbk', parse_dates=[0], usecols=[0, 3], skiprows=1, names=['日期', '上证50收益率'])[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.merge(index_data, on='日期')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.sort_values(['股票代码', '日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.reset_index(drop=True, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['超额收益率'] = data['回报率(不考虑分红)'] - data['上证50收益率']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['ret20'] = data.groupby('股票代码')['超额收益率'].rolling(20).sum().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['ret60'] = data.groupby('股票代码')['超额收益率'].rolling(60).sum().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['volitility'] = data.groupby('股票代码')['回报率(不考虑分红)'].rolling(20).std().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "size_volume = pd.read_csv('市值、成交量.csv', usecols=[0, 1, 3, 4], parse_dates=[0], skiprows=1, names=['日期', '股票代码', '市值', '成交量'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.merge(size_volume, on=['股票代码', '日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset = pd.read_csv('所有者权益(1).csv', encoding='utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset['report_quarter'] = net_asset['report_quarter'] % 1000 * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset['report_day'] = 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset.rename(columns={'report_year': 'year', 'report_quarter': 'month', 'report_day': 'day'}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset.index = pd.to_datetime(net_asset[['year', 'month', 'day']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset_daily = pd.DataFrame()\n",
    "tickers = pd.unique(net_asset['stock_code'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "for ticker in tickers:\n",
    "    tk_df = net_asset[net_asset['stock_code'] == ticker]\n",
    "    tk_df = tk_df.resample('D').ffill()\n",
    "    net_asset_daily = pd.concat([net_asset_daily, tk_df], axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset_daily = net_asset_daily.iloc[:, [0, 1, 4]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset_daily.reset_index(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "net_asset_daily.rename(columns={'index': '日期', 'stock_code': '股票代码'}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.merge(net_asset_daily, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['账面市值比'] = data['tse'] / data['市值']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "con_roe = pd.read_csv('一致预期净资产收益率.csv', skiprows=1, usecols=[0, 1, 3], names=['日期', '股票代码', 'con_roe'], parse_dates=[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.merge(con_roe, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "con_rating_strength = pd.read_csv('一致预期评级强度.csv', usecols=[0, 1, 3], skiprows=1, names=['日期', '股票代码', 'con_rating_strength'], parse_dates=[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.merge(con_rating_strength, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "report_num_m = pd.read_csv('个股月报告数.csv', usecols=[0, 1, 3], skiprows=1, names=['日期', '股票代码', 'report_num_m'], parse_dates=[0])\n",
    "data = data.merge(report_num_m, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "relative_report_num_10 = pd.read_csv('个股10日相对报告数.csv', usecols=[0, 1, 3], skiprows=1, names=['日期', '股票代码', 'relative_report_num_10'], parse_dates=[0])\n",
    "data = data.merge(relative_report_num_10, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "con_eps_roll = pd.read_csv('滚动一致预期每股收益.csv', skiprows=1, names=['股票代码', '日期', 'con_eps_roll'], parse_dates=[1])\n",
    "data = data.merge(con_eps_roll, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "eps = pd.read_csv('基本每股收益.csv', encoding='utf8')\n",
    "eps['report_quarter'] = eps['report_quarter'] % 1000 * 3\n",
    "eps['report_day'] = 30\n",
    "eps.rename(columns={'report_year': 'year', 'report_quarter': 'month', 'report_day': 'day'}, inplace=True)\n",
    "eps.index = pd.to_datetime(eps[['year', 'month', 'day']])\n",
    "eps_daily = pd.DataFrame()\n",
    "for ticker in tickers:\n",
    "    tk_df = eps[eps['stock_code'] == ticker]\n",
    "    tk_df = tk_df.resample('D').ffill()\n",
    "    eps_daily = pd.concat([eps_daily, tk_df], axis=0)\n",
    "eps_daily = eps_daily.iloc[:, [0, 3]]\n",
    "eps_daily.reset_index(inplace=True)\n",
    "eps_daily.rename(columns={'index': '日期', 'stock_code': '股票代码'}, inplace=True)\n",
    "data = data.merge(eps_daily, on=['日期', '股票代码'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['Exc_eps'] = data['con_eps_roll'] - data['bas_eps']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['Exc20'] = data.groupby('股票代码')['Exc_eps'].rolling(20).mean().values\n",
    "data['Exc60'] = data.groupby('股票代码')['Exc_eps'].rolling(60).mean().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "end_date = pd.to_datetime(20200123, format='%Y%m%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2020-01-23 00:00:00')"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "end_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "senti_path = 'all_result'\n",
    "senti_file_list = os.listdir(senti_path)\n",
    "senti_data = pd.DataFrame()\n",
    "for file in senti_file_list:\n",
    "    senti = pd.read_csv(os.path.join(senti_path, file), usecols=[0] + list(range(9, 17)), parse_dates=[0], encoding='gbk')[::-1]\n",
    "    senti.rename(columns={'post_date': '日期'}, inplace=True)\n",
    "    senti = senti[senti['日期'] <= end_date]\n",
    "    senti_count = senti.groupby('日期')['情感'].value_counts().unstack().fillna(0)\n",
    "    senti_count1 = senti.groupby('日期')['主题一'].value_counts().unstack().fillna(0)\n",
    "    senti_count2 = senti.groupby('日期')['主题二'].value_counts().unstack().fillna(0)\n",
    "    senti_count3 = senti.groupby('日期')['主题三'].value_counts().unstack().fillna(0)\n",
    "    senti_count4 = senti.groupby('日期')['主题四'].value_counts().unstack().fillna(0)\n",
    "    senti_count5 = senti.groupby('日期')['主题五'].value_counts().unstack().fillna(0)\n",
    "    senti_count6 = senti.groupby('日期')['主题六'].value_counts().unstack().fillna(0)\n",
    "    senti_count7 = senti.groupby('日期')['主题七'].value_counts().unstack().fillna(0)\n",
    "    senti_count = senti_count.rolling(20).sum()\n",
    "    senti_count1 = senti_count1.rolling(20).sum()\n",
    "    senti_count2 = senti_count2.rolling(20).sum()\n",
    "    senti_count3 = senti_count3.rolling(20).sum()\n",
    "    senti_count4 = senti_count4.rolling(20).sum()\n",
    "    senti_count5 = senti_count5.rolling(20).sum()\n",
    "    senti_count6 = senti_count6.rolling(20).sum()\n",
    "    senti_count7 = senti_count7.rolling(20).sum()\n",
    "    senti_count['Opin1'] = np.log((1 + senti_count['积极']) / (1 + senti_count['消极']))\n",
    "    senti_count['Opin2'] = (senti_count['积极'] - senti_count['消极']) / (senti_count['积极'] + senti_count['消极'] + senti_count['中性'])\n",
    "    senti_count = senti_count[['Opin1', 'Opin2']]\n",
    "    \n",
    "    senti_count1['主题一Opin1'] = np.log((1 + senti_count1['积极']) / (1 + senti_count1['消极']))\n",
    "    senti_count1['主题一Opin2'] = (senti_count1['积极'] - senti_count1['消极']) / (senti_count1['积极'] + senti_count1['消极'] + senti_count1['中性'])\n",
    "    senti_count1['主题一pos'] = senti_count1['积极'] / (senti_count1['积极'] + senti_count1['消极'] + senti_count1['中性'])\n",
    "    senti_count1['主题一neg'] = senti_count1['消极'] / (senti_count1['积极'] + senti_count1['消极'] + senti_count1['中性'])\n",
    "    senti_count1 = senti_count1[['主题一Opin1', '主题一Opin2', '主题一pos', '主题一neg']]\n",
    "    \n",
    "    senti_count2['主题二Opin1'] = np.log((1 + senti_count2['积极']) / (1 + senti_count2['消极']))\n",
    "    senti_count2['主题二Opin2'] = (senti_count2['积极'] - senti_count2['消极']) / (senti_count2['积极'] + senti_count2['消极'] + senti_count2['中性'])\n",
    "    senti_count2['主题二pos'] = senti_count2['积极'] / (senti_count2['积极'] + senti_count2['消极'] + senti_count2['中性'])\n",
    "    senti_count2['主题二neg'] = senti_count2['消极'] / (senti_count2['积极'] + senti_count2['消极'] + senti_count2['中性'])\n",
    "    senti_count2 = senti_count2[['主题二Opin1', '主题二Opin2', '主题二pos', '主题二neg']]\n",
    "    \n",
    "    senti_count3['主题三Opin1'] = np.log((1 + senti_count3['积极']) / (1 + senti_count3['消极']))\n",
    "    senti_count3['主题三Opin2'] = (senti_count3['积极'] - senti_count3['消极']) / (senti_count3['积极'] + senti_count3['消极'] + senti_count3['中性'])\n",
    "    senti_count3['主题三pos'] = senti_count3['积极'] / (senti_count3['积极'] + senti_count3['消极'] + senti_count3['中性'])\n",
    "    senti_count3['主题三neg'] = senti_count3['消极'] / (senti_count3['积极'] + senti_count3['消极'] + senti_count3['中性'])\n",
    "    senti_count3 = senti_count3[['主题三Opin1', '主题三Opin2', '主题三pos', '主题三neg']]\n",
    "    \n",
    "    senti_count4['主题四Opin1'] = np.log((1 + senti_count4['积极']) / (1 + senti_count4['消极']))\n",
    "    senti_count4['主题四Opin2'] = (senti_count4['积极'] - senti_count4['消极']) / (senti_count4['积极'] + senti_count4['消极'] + senti_count4['中性'])\n",
    "    senti_count4['主题四pos'] = senti_count4['积极'] / (senti_count4['积极'] + senti_count4['消极'] + senti_count4['中性'])\n",
    "    senti_count4['主题四neg'] = senti_count4['消极'] / (senti_count4['积极'] + senti_count4['消极'] + senti_count4['中性'])\n",
    "    senti_count4 = senti_count4[['主题四Opin1', '主题四Opin2', '主题四pos', '主题四neg']]\n",
    "    \n",
    "    senti_count5['主题五Opin1'] = np.log((1 + senti_count5['积极']) / (1 + senti_count5['消极']))\n",
    "    senti_count5['主题五Opin2'] = (senti_count5['积极'] - senti_count5['消极']) / (senti_count5['积极'] + senti_count5['消极'] + senti_count5['中性'])\n",
    "    senti_count5['主题五pos'] = senti_count5['积极'] / (senti_count5['积极'] + senti_count5['消极'] + senti_count5['中性'])\n",
    "    senti_count5['主题五neg'] = senti_count5['消极'] / (senti_count5['积极'] + senti_count5['消极'] + senti_count5['中性'])\n",
    "    senti_count5 = senti_count5[['主题五Opin1', '主题五Opin2', '主题五pos', '主题五neg']]\n",
    "    \n",
    "    senti_count6['主题六Opin1'] = np.log((1 + senti_count6['积极']) / (1 + senti_count6['消极']))\n",
    "    senti_count6['主题六Opin2'] = (senti_count6['积极'] - senti_count6['消极']) / (senti_count6['积极'] + senti_count6['消极'] + senti_count6['中性'])\n",
    "    senti_count6['主题六pos'] = senti_count6['积极'] / (senti_count6['积极'] + senti_count6['消极'] + senti_count6['中性'])\n",
    "    senti_count6['主题六neg'] = senti_count6['消极'] / (senti_count6['积极'] + senti_count6['消极'] + senti_count6['中性'])\n",
    "    senti_count6 = senti_count6[['主题六Opin1', '主题六Opin2', '主题六pos', '主题六neg']]\n",
    "    \n",
    "    senti_count7['主题七Opin1'] = np.log((1 + senti_count7['积极']) / (1 + senti_count7['消极']))\n",
    "    senti_count7['主题七Opin2'] = (senti_count7['积极'] - senti_count7['消极']) / (senti_count7['积极'] + senti_count7['消极'] + senti_count7['中性'])\n",
    "    senti_count7['主题七pos'] = senti_count7['积极'] / (senti_count7['积极'] + senti_count7['消极'] + senti_count7['中性'])\n",
    "    senti_count7['主题七neg'] = senti_count7['消极'] / (senti_count7['积极'] + senti_count7['消极'] + senti_count7['中性'])\n",
    "    senti_count7 = senti_count7[['主题七Opin1', '主题七Opin2', '主题七pos', '主题七neg']]\n",
    "    \n",
    "    senti = pd.concat([senti_count, senti_count1, senti_count2, senti_count3, senti_count4, senti_count5, senti_count6, senti_count7], axis=1)\n",
    "    senti['股票代码'] = int(file.split('.')[0])\n",
    "    senti.reset_index(inplace=True)\n",
    "    senti_data = pd.concat([senti_data, senti])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>Opin1</th>\n",
       "      <th>Opin2</th>\n",
       "      <th>主题一Opin1</th>\n",
       "      <th>主题一Opin2</th>\n",
       "      <th>主题一pos</th>\n",
       "      <th>主题一neg</th>\n",
       "      <th>主题二Opin1</th>\n",
       "      <th>主题二Opin2</th>\n",
       "      <th>主题二pos</th>\n",
       "      <th>...</th>\n",
       "      <th>主题五neg</th>\n",
       "      <th>主题六Opin1</th>\n",
       "      <th>主题六Opin2</th>\n",
       "      <th>主题六pos</th>\n",
       "      <th>主题六neg</th>\n",
       "      <th>主题七Opin1</th>\n",
       "      <th>主题七Opin2</th>\n",
       "      <th>主题七pos</th>\n",
       "      <th>主题七neg</th>\n",
       "      <th>股票代码</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-02-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>600016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>600016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-03-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>600016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-03-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>600016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>600016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1529</th>\n",
       "      <td>2016-05-16</td>\n",
       "      <td>-0.204794</td>\n",
       "      <td>-0.085470</td>\n",
       "      <td>-0.080043</td>\n",
       "      <td>-0.024390</td>\n",
       "      <td>0.268293</td>\n",
       "      <td>0.292683</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.457627</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.747214</td>\n",
       "      <td>-0.294118</td>\n",
       "      <td>0.235294</td>\n",
       "      <td>0.529412</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>601336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1530</th>\n",
       "      <td>2016-05-17</td>\n",
       "      <td>-0.209092</td>\n",
       "      <td>-0.087719</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.457627</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.693147</td>\n",
       "      <td>-0.277778</td>\n",
       "      <td>0.250000</td>\n",
       "      <td>0.527778</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>601336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1531</th>\n",
       "      <td>2016-05-18</td>\n",
       "      <td>-0.206336</td>\n",
       "      <td>-0.085271</td>\n",
       "      <td>-0.154151</td>\n",
       "      <td>-0.045455</td>\n",
       "      <td>0.250000</td>\n",
       "      <td>0.295455</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.459016</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.559616</td>\n",
       "      <td>-0.225000</td>\n",
       "      <td>0.275000</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>-0.597837</td>\n",
       "      <td>-0.257143</td>\n",
       "      <td>0.285714</td>\n",
       "      <td>0.542857</td>\n",
       "      <td>601336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1532</th>\n",
       "      <td>2016-05-19</td>\n",
       "      <td>-0.271934</td>\n",
       "      <td>-0.111940</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.138150</td>\n",
       "      <td>0.066667</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.646627</td>\n",
       "      <td>-0.256410</td>\n",
       "      <td>0.256410</td>\n",
       "      <td>0.512821</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>601336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1533</th>\n",
       "      <td>2016-05-20</td>\n",
       "      <td>-0.308735</td>\n",
       "      <td>-0.126866</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.143101</td>\n",
       "      <td>0.068966</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.597837</td>\n",
       "      <td>-0.243243</td>\n",
       "      <td>0.270270</td>\n",
       "      <td>0.513514</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>601336</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>37057 rows × 32 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期     Opin1     Opin2  主题一Opin1  主题一Opin2    主题一pos    主题一neg  \\\n",
       "0    2014-02-27       NaN       NaN       NaN       NaN       NaN       NaN   \n",
       "1    2014-02-28       NaN       NaN       NaN       NaN       NaN       NaN   \n",
       "2    2014-03-01       NaN       NaN       NaN       NaN       NaN       NaN   \n",
       "3    2014-03-02       NaN       NaN       NaN       NaN       NaN       NaN   \n",
       "4    2014-03-03       NaN       NaN       NaN       NaN       NaN       NaN   \n",
       "...         ...       ...       ...       ...       ...       ...       ...   \n",
       "1529 2016-05-16 -0.204794 -0.085470 -0.080043 -0.024390  0.268293  0.292683   \n",
       "1530 2016-05-17 -0.209092 -0.087719       NaN       NaN       NaN       NaN   \n",
       "1531 2016-05-18 -0.206336 -0.085271 -0.154151 -0.045455  0.250000  0.295455   \n",
       "1532 2016-05-19 -0.271934 -0.111940       NaN       NaN       NaN       NaN   \n",
       "1533 2016-05-20 -0.308735 -0.126866       NaN       NaN       NaN       NaN   \n",
       "\n",
       "      主题二Opin1  主题二Opin2    主题二pos  ...  主题五neg  主题六Opin1  主题六Opin2    主题六pos  \\\n",
       "0          NaN       NaN       NaN  ...     NaN       NaN       NaN       NaN   \n",
       "1          NaN       NaN       NaN  ...     NaN       NaN       NaN       NaN   \n",
       "2          NaN       NaN       NaN  ...     NaN       NaN       NaN       NaN   \n",
       "3          NaN       NaN       NaN  ...     NaN       NaN       NaN       NaN   \n",
       "4          NaN       NaN       NaN  ...     NaN       NaN       NaN       NaN   \n",
       "...        ...       ...       ...  ...     ...       ...       ...       ...   \n",
       "1529  0.000000  0.000000  0.457627  ...     NaN -0.747214 -0.294118  0.235294   \n",
       "1530  0.000000  0.000000  0.457627  ...     NaN -0.693147 -0.277778  0.250000   \n",
       "1531  0.000000  0.000000  0.459016  ...     NaN -0.559616 -0.225000  0.275000   \n",
       "1532  0.138150  0.066667  0.500000  ...     NaN -0.646627 -0.256410  0.256410   \n",
       "1533  0.143101  0.068966  0.500000  ...     NaN -0.597837 -0.243243  0.270270   \n",
       "\n",
       "        主题六neg  主题七Opin1  主题七Opin2    主题七pos    主题七neg    股票代码  \n",
       "0          NaN       NaN       NaN       NaN       NaN  600016  \n",
       "1          NaN       NaN       NaN       NaN       NaN  600016  \n",
       "2          NaN       NaN       NaN       NaN       NaN  600016  \n",
       "3          NaN       NaN       NaN       NaN       NaN  600016  \n",
       "4          NaN       NaN       NaN       NaN       NaN  600016  \n",
       "...        ...       ...       ...       ...       ...     ...  \n",
       "1529  0.529412       NaN       NaN       NaN       NaN  601336  \n",
       "1530  0.527778       NaN       NaN       NaN       NaN  601336  \n",
       "1531  0.500000 -0.597837 -0.257143  0.285714  0.542857  601336  \n",
       "1532  0.512821       NaN       NaN       NaN       NaN  601336  \n",
       "1533  0.513514       NaN       NaN       NaN       NaN  601336  \n",
       "\n",
       "[37057 rows x 32 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "senti_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = senti_data.merge(data, on=['股票代码', '日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.set_index(['股票代码', '日期'], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['const'] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\pandas\\core\\series.py:679: RuntimeWarning: divide by zero encountered in log\n",
      "  result = getattr(ufunc, method)(*inputs, **kwargs)\n"
     ]
    }
   ],
   "source": [
    "data['市值'] = np.log(data['市值'])\n",
    "data['成交量'] = np.log(data['成交量'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.dropna(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['成交量'] = data['成交量'].groupby('股票代码').transform(lambda x: (x - x.mean()) / x.std())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Opin1', 'Opin2', '主题一Opin1', '主题一Opin2', '主题一pos', '主题一neg',\n",
       "       '主题二Opin1', '主题二Opin2', '主题二pos', '主题二neg', '主题三Opin1', '主题三Opin2',\n",
       "       '主题三pos', '主题三neg', '主题四Opin1', '主题四Opin2', '主题四pos', '主题四neg',\n",
       "       '主题五Opin1', '主题五Opin2', '主题五pos', '主题五neg', '主题六Opin1', '主题六Opin2',\n",
       "       '主题六pos', '主题六neg', '主题七Opin1', '主题七Opin2', '主题七pos', '主题七neg',\n",
       "       '回报率(不考虑分红)', '上证50收益率', '超额收益率', 'ret20', 'ret60', 'volitility', '市值',\n",
       "       '成交量', 'stock_name', 'tse', '账面市值比', 'con_roe', 'con_rating_strength',\n",
       "       'report_num_m', 'relative_report_num_10', 'con_eps_roll', 'bas_eps',\n",
       "       'Exc_eps', 'Exc20', 'Exc60', 'const'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "from linearmodels.panel import PanelOLS\n",
    "import statsmodels.api as sm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3099"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exog_vars = ['Opin1', 'Opin2', 'volitility', '市值', '账面市值比', '成交量', 'report_num_m', 'relative_report_num_10', 'con_rating_strength', 'con_roe', 'const']\n",
    "exog = data[exog_vars]\n",
    "mod = PanelOLS(data['ret60'], exog, entity_effects=True, time_effects=True)\n",
    "result = mod.fit()\n",
    "with open('回归结果/未分类三个月超额收益.txt', 'w') as f:\n",
    "    f.write(str(result))\n",
    "    f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>PanelOLS Estimation Summary</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>          <td>ret60</td>      <th>  R-squared:         </th>    <td>0.2052</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Estimator:</th>            <td>PanelOLS</td>     <th>  R-squared (Between):</th>   <td>-9.5527</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Observations:</th>       <td>1269</td>       <th>  R-squared (Within):</th>    <td>-0.0719</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>             <td>Tue, May 19 2020</td> <th>  R-squared (Overall):</th>   <td>-0.5033</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                 <td>20:38:08</td>     <th>  Log-likelihood     </th>    <td>-2964.1</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Cov. Estimator:</th>      <td>Unadjusted</td>    <th>                     </th>       <td></td>     \n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                          <td></td>         <th>  F-statistic:       </th>    <td>9.2963</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Entities:</th>                 <td>6</td>        <th>  P-value            </th>    <td>0.0000</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Avg Obs:</th>               <td>211.50</td>      <th>  Distribution:      </th>   <td>F(10,360)</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Min Obs:</th>               <td>44.000</td>      <th>                     </th>       <td></td>     \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Max Obs:</th>               <td>509.00</td>      <th>  F-statistic (robust):</th>  <td>9.2963</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                          <td></td>         <th>  P-value            </th>    <td>0.0000</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time periods:</th>            <td>894</td>       <th>  Distribution:      </th>   <td>F(10,360)</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Avg Obs:</th>               <td>1.4195</td>      <th>                     </th>       <td></td>     \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Min Obs:</th>               <td>1.0000</td>      <th>                     </th>       <td></td>     \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Max Obs:</th>               <td>4.0000</td>      <th>                     </th>       <td></td>     \n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                          <td></td>         <th>                     </th>       <td></td>     \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<caption>Parameter Estimates</caption>\n",
       "<tr>\n",
       "             <td></td>            <th>Parameter</th> <th>Std. Err.</th> <th>T-stat</th>  <th>P-value</th> <th>Lower CI</th> <th>Upper CI</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Opin1</th>                   <td>-80.551</td>   <td>32.794</td>   <td>-2.4563</td> <td>0.0145</td>   <td>-145.04</td>  <td>-16.059</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Opin2</th>                   <td>218.00</td>    <td>78.899</td>   <td>2.7631</td>  <td>0.0060</td>   <td>62.841</td>   <td>373.16</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>volitility</th>              <td>-105.29</td>   <td>41.926</td>   <td>-2.5114</td> <td>0.0125</td>   <td>-187.74</td>  <td>-22.840</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>市值</th>                      <td>-15.532</td>   <td>3.2067</td>   <td>-4.8436</td> <td>0.0000</td>   <td>-21.838</td>  <td>-9.2258</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>账面市值比</th>                   <td>-0.0016</td>   <td>0.0003</td>   <td>-4.6419</td> <td>0.0000</td>   <td>-0.0022</td>  <td>-0.0009</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>成交量</th>                     <td>0.0600</td>    <td>0.4258</td>   <td>0.1409</td>  <td>0.8881</td>   <td>-0.7774</td>  <td>0.8973</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>report_num_m</th>            <td>-0.3487</td>   <td>0.1000</td>   <td>-3.4864</td> <td>0.0006</td>   <td>-0.5454</td>  <td>-0.1520</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>relative_report_num_10</th>  <td>0.9738</td>    <td>0.3076</td>   <td>3.1659</td>  <td>0.0017</td>   <td>0.3689</td>   <td>1.5787</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>con_rating_strength</th>     <td>-6.3615</td>   <td>3.6406</td>   <td>-1.7474</td> <td>0.0814</td>   <td>-13.521</td>  <td>0.7980</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>con_roe</th>                 <td>0.2943</td>    <td>0.2972</td>   <td>0.9902</td>  <td>0.3227</td>   <td>-0.2902</td>  <td>0.8787</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>const</th>                   <td>274.93</td>    <td>55.372</td>   <td>4.9651</td>  <td>0.0000</td>   <td>166.03</td>   <td>383.82</td> \n",
       "</tr>\n",
       "</table><br/><br/>F-test for Poolability: 11.736<br/>P-value: 0.0000<br/>Distribution: F(898,360)<br/><br/>Included effects: Entity, Time"
      ],
      "text/plain": [
       "<class 'linearmodels.compat.statsmodels.Summary'>\n",
       "\"\"\"\n",
       "                          PanelOLS Estimation Summary                           \n",
       "================================================================================\n",
       "Dep. Variable:                  ret60   R-squared:                        0.2052\n",
       "Estimator:                   PanelOLS   R-squared (Between):             -9.5527\n",
       "No. Observations:                1269   R-squared (Within):              -0.0719\n",
       "Date:                Tue, May 19 2020   R-squared (Overall):             -0.5033\n",
       "Time:                        20:38:08   Log-likelihood                   -2964.1\n",
       "Cov. Estimator:            Unadjusted                                           \n",
       "                                        F-statistic:                      9.2963\n",
       "Entities:                           6   P-value                           0.0000\n",
       "Avg Obs:                       211.50   Distribution:                  F(10,360)\n",
       "Min Obs:                       44.000                                           \n",
       "Max Obs:                       509.00   F-statistic (robust):             9.2963\n",
       "                                        P-value                           0.0000\n",
       "Time periods:                     894   Distribution:                  F(10,360)\n",
       "Avg Obs:                       1.4195                                           \n",
       "Min Obs:                       1.0000                                           \n",
       "Max Obs:                       4.0000                                           \n",
       "                                                                                \n",
       "                                   Parameter Estimates                                    \n",
       "==========================================================================================\n",
       "                        Parameter  Std. Err.     T-stat    P-value    Lower CI    Upper CI\n",
       "------------------------------------------------------------------------------------------\n",
       "Opin1                     -80.551     32.794    -2.4563     0.0145     -145.04     -16.059\n",
       "Opin2                      218.00     78.899     2.7631     0.0060      62.841      373.16\n",
       "volitility                -105.29     41.926    -2.5114     0.0125     -187.74     -22.840\n",
       "市值                        -15.532     3.2067    -4.8436     0.0000     -21.838     -9.2258\n",
       "账面市值比                     -0.0016     0.0003    -4.6419     0.0000     -0.0022     -0.0009\n",
       "成交量                        0.0600     0.4258     0.1409     0.8881     -0.7774      0.8973\n",
       "report_num_m              -0.3487     0.1000    -3.4864     0.0006     -0.5454     -0.1520\n",
       "relative_report_num_10     0.9738     0.3076     3.1659     0.0017      0.3689      1.5787\n",
       "con_rating_strength       -6.3615     3.6406    -1.7474     0.0814     -13.521      0.7980\n",
       "con_roe                    0.2943     0.2972     0.9902     0.3227     -0.2902      0.8787\n",
       "const                      274.93     55.372     4.9651     0.0000      166.03      383.82\n",
       "==========================================================================================\n",
       "\n",
       "F-test for Poolability: 11.736\n",
       "P-value: 0.0000\n",
       "Distribution: F(898,360)\n",
       "\n",
       "Included effects: Entity, Time\n",
       "\"\"\""
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result.summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exog_vars = ['主题一Opin2', '主题二Opin2', '主题三Opin2', '市值', 'const']\n",
    "exog = data[exog_vars]\n",
    "mod = PanelOLS(data['成交量'], exog, entity_effects=True, time_effects=True)\n",
    "result = mod.fit()\n",
    "with open('回归结果/成交量——Opin2主题分类回归结果.txt', 'w') as f:\n",
    "    f.write(str(result))\n",
    "    f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exog_vars = ['Opin1', '市值', 'const']\n",
    "exog = data[exog_vars]\n",
    "mod = PanelOLS(data['成交量'], exog, entity_effects=True, time_effects=True)\n",
    "result = mod.fit()\n",
    "with open('回归结果/成交量——Opin1未经主题分类回归结果.txt', 'w') as f:\n",
    "    f.write(str(result))\n",
    "    f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exog_vars = ['Opin2', '市值', 'const']\n",
    "exog = data[exog_vars]\n",
    "mod = PanelOLS(data['成交量'], exog, entity_effects=True, time_effects=True)\n",
    "result = mod.fit()\n",
    "with open('回归结果/成交量——Opin2未经主题分类回归结果.txt', 'w') as f:\n",
    "    f.write(str(result))\n",
    "    f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
